const Mock = require('mockjs')
const Random = Mock.Random

const code = 200;

//顶部广告轮播
Mock.mock('/ad','get',function () {
    let ad = [];
    for (let i = 0;i<=3;i++){
        obj = {
            url:Random.url('http'),
            img:Random.image('300x150', '#02adea', 'Hello' + i)
        }
        ad.push(obj)
    }

    return {
        code:code,
        message:'success',
        data:ad
    }
});
//新闻列表
Mock.mock('/news-list','get',function () {
    let newsList = [];
    for (let i = 0;i<=10;i++){
        obj = {
            id:Random.integer( 1111, 9999 ),
            title:Random.ctitle(5, 10),
            img_url:Random.image('42x42', '#02adea',  i),
            add_time:Random.date('yyyy-MM-dd'),
            click:Random.integer( 1111, 9999 ),
            zhaiyao:Random.cparagraph()
        }
        newsList.push(obj)
    }

    return {
        code:code,
        message:'success',
        data:newsList
    }
})

//新闻详情
//TODO::这里正则匹配有问题
Mock.mock('/newsinfo/','get',option => {

    return {
        code:code,
        message:'success',
        data:{
            id:Random.integer( 1111, 9999 ),
            title:Random.ctitle(5, 10),
            // img_url:Random.image('42x42', '#02adea',  i),
            add_time:Random.date('yyyy-MM-dd'),
            click:Random.integer( 1111, 9999 ),
            content:Random.cparagraph()
        }
    }
})

//评论列表
Mock.mock('/commnet-list/','get',function () {
    let list = [];
    for (let i = 0;i<=10;i++){
        obj = {
            id:Random.integer( 1111, 9999 ),
            content:Random.ctitle(5, 10),
            user_name:Random.ctitle(),
            add_time:Random.date('yyyy-MM-dd'),
        }
        list.push(obj)
    }

    return {
        code:code,
        message:'success',
        data:list
    }
})

//发表评论
//TODO::这里正则匹配有问题
Mock.mock('/publish-comment/','post',option => {

    return {
        code:code,
        message:'success',
        data:{
            id:Random.integer( 1111, 9999 ),
            user_name:Random.ctitle(),
            add_time:Random.date('yyyy-MM-dd'),
            content:Random.cparagraph()
        }
    }
})

//图片分类列表
Mock.mock('/photo-category-list/','get',function () {
    let list = [];
    for (let i = 0;i<=5;i++){
        obj = {
            id:Random.integer( 11111, 99999 ),
            title:Random.ctitle(),
        }
        list.push(obj)
    }

    return {
        code:code,
        message:'success',
        data:list
    }
})

//图片列表
Mock.mock('/get-photos/','get',function () {
    let list = [];
    for (let i = 0;i<=20;i++){
        obj = {
            id:Random.integer( 11111, 99999 ),
            title:Random.ctitle(10,20),
            img_url:Random.image('300x350', '#02adea', 'Hello' + i),
            desc:Random.paragraph()
        }
        list.push(obj)
    }

    return {
        code:code,
        message:'success',
        data:list
    }
})

//图片详情
Mock.mock('/photo-info/','get',function () {
    let list = [];
    for (let i = 0;i<=5;i++){
        list.push({
            src:Random.image('300x400', '#02adea', 'Hello' + i),
            msrc:Random.image('100x100', '#02adea', 'Hello' + i),
            w:300,
            h:400,
        })
    }

    return {
        code:code,
        message:'success',
        data:{
            id:Random.integer( 1111, 9999 ),
            title:Random.ctitle(5, 10),
            img:list,
            add_time:Random.date('yyyy-MM-dd'),
            click:Random.integer( 1111, 9999 ),
            content:Random.paragraph()
        }
    }
})
